// src/views/Login.js

import request from "@/axios/request";
import { ElMessage } from "element-plus";

export default {
  name: "Login",
  data() {
    return {
      identity: "",
      form: {
        username: "",
        password: "",
        identity: "",
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" },
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
        identity: [{ required: true, message: "请选择身份", trigger: "blur" }],
      },
    };
  },
  computed: {
    disabled() {
      const { username, password, identity } = this.form;
      return Boolean(username && password && identity);
    },
  },
  methods: {
    // 原有的登录方法
    login() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.identity = this.form.identity;
          request.post("/" + this.identity + "/login", this.form).then((res) => {
            if (res.code === 200) {
              ElMessage({
                message: "登录成功",
                type: "success",
              });
              window.sessionStorage.setItem("userInfo", JSON.stringify(res.data));
              window.sessionStorage.setItem("identity", JSON.stringify(this.form.identity));
              this.$router.push("/" + this.form.identity + "Home");
            } else {
              ElMessage({
                message: res.msg,
                type: "error",
              });
            }
          });
        }
      });
    },
    // 新增的跳转方法
    goToFaceRecognition() {
      // 使用 window.location.href 进行完整的页面跳转
      window.location.href = 'http://localhost:8085/3.html';
    },
  },
};
